﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Common;
using CCWin.SkinControl;

namespace 生命体征测试仪
{
    public partial class formMedicalQuery : formBase
    {
        public formMedicalQuery()
        {
            InitializeComponent();
        }

        private void skinButton13_Click(object sender, EventArgs e)
        {
            leftTime = 60;
            for (int i = 1; i < 13; i++)
            {
                SetBt(i, "");
            }
            formTimeRange f = new formTimeRange();
            if (f.ShowDialog() == DialogResult.OK)
            {
                MedicalResultList ret= WebWork.QueryMedicalResultList(formMain.PType.ToString(), formMain.curUser.ID, formTimeRange.t1.ToString("yyyyMMdd"), formTimeRange.t2.AddDays(1).ToString("yyyyMMdd"));;
                if (ret == null)
                {
                    MessageBox.Show("向服务器查询数据失败");
                    return;
                }
                if (ret.list==null || ret.list.Count == 0)
                    lbNull.Visible = true;
                else
                {
                    lbNull.Visible = false;
                    for (int i = 0; i < 12 && i < ret.list.Count; i++)
                    {
                        SetBt(i + 1, ret.list[i].time);
                    }
                }
            }                
        }
        void SetBt(int i, string str)
        {
            switch (i)
            {
                case 1:
                    if(str=="")
                        skinButton1.Visible = false;
                    else
                    {
                        skinButton1.Visible = true;
                        skinButton1.Text = str;
                    }
                    break;
                case 2:
                    if (str == "")
                        skinButton2.Visible = false;
                    else
                    {
                        skinButton2.Visible = true;
                        skinButton2.Text = str;
                    }
                    break;
                case 3:
                    if (str == "")
                        skinButton3.Visible = false;
                    else
                    {
                        skinButton3.Visible = true;
                        skinButton3.Text = str;
                    }
                    break;
                case 4:
                    if (str == "")
                        skinButton4.Visible = false;
                    else
                    {
                        skinButton4.Visible = true;
                        skinButton4.Text = str;
                    }
                    break;
                case 5:
                    if (str == "")
                        skinButton5.Visible = false;
                    else
                    {
                        skinButton5.Visible = true;
                        skinButton5.Text = str;
                    }
                    break;
                case 6:
                    if (str == "")
                        skinButton6.Visible = false;
                    else
                    {
                        skinButton6.Visible = true;
                        skinButton6.Text = str;
                    }
                    break;
                case 7:
                    if (str == "")
                        skinButton7.Visible = false;
                    else
                    {
                        skinButton7.Visible = true;
                        skinButton7.Text = str;
                    }
                    break;
                case 8:
                    if (str == "")
                        skinButton8.Visible = false;
                    else
                    {
                        skinButton8.Visible = true;
                        skinButton8.Text = str;
                    }
                    break;
                case 9:
                    if (str == "")
                        skinButton9.Visible = false;
                    else
                    {
                        skinButton9.Visible = true;
                        skinButton9.Text = str;
                    }
                    break;
                case 10:
                    if (str == "")
                        skinButton10.Visible = false;
                    else
                    {
                        skinButton10.Visible = true;
                        skinButton10.Text = str;
                    }
                    break;
                case 11:
                    if (str == "")
                        skinButton11.Visible = false;
                    else
                    {
                        skinButton11.Visible = true;
                        skinButton11.Text = str;
                    }
                    break;
                case 12:
                    if (str == "")
                        skinButton12.Visible = false;
                    else
                    {
                        skinButton12.Visible = true;
                        skinButton12.Text = str;
                    }
                    break;
            }
        }

        private void skinButton14_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void formMedicalQuery_Load(object sender, EventArgs e)
        {
            leftTime = 60;
            lbName.Text = formMain.curUser.Name;
            MedicalResultList ret= WebWork.QueryMedicalResultList(formMain.PType.ToString(), formMain.curUser.ID);;
            if (ret == null)
            {
                MessageBox.Show("向服务器查询数据失败");
                return;
            }
            if (ret.list == null|| ret.list.Count == 0)
                lbNull.Visible = true;
            else
            {
                lbNull.Visible = false;
                for (int i = 0; i < 12 && i < ret.list.Count; i++)
                {
                    SetBt(i + 1, ret.list[i].time);
                }
            }
        }

        private void skinButton15_Click(object sender, EventArgs e)
        {
            leftTime = 60;
            for (int i = 1; i < 13; i++)
            {
                SetBt(i, "");
            }
            MedicalResultList ret= WebWork.QueryMedicalResultList(formMain.PType.ToString(), formMain.curUser.ID);;
            if (ret == null)
            {
                MessageBox.Show("向服务器查询数据失败");
                return;
            }
            if (ret.list == null|| ret.list.Count == 0)
                lbNull.Visible = true;
            else
            {
                lbNull.Visible = false;
                for (int i = 0; i < 12 && i < ret.list.Count; i++)
                {
                    SetBt(i + 1, ret.list[i].time);
                }
            }
        }

        private void skinButton1_Click(object sender, EventArgs e)
        {
            SkinButton bt=(SkinButton)sender;
            MedicalResultData m=WebWork.QueryMedicalResult(formMain.PType.ToString(),formMain.curUser.ID, bt.Text);            
            if (m == null)
            {
                MessageBox.Show("查询体检结果失败");
                return;
            }
            timer1.Enabled = false;
            formMedicalResult f = new formMedicalResult(m);
            f.ShowDialog();
            leftTime = 60;
            timer1.Enabled = true;
//             DateTime t = Convert.ToDateTime(bt.Text);
//             MedicalResultData m=WebWork.QueryMedicalResult(formMain.curUser.ID,t.ToString("yyyyMMddHHmmss"));
        }
        int leftTime;
        private void timer1_Tick(object sender, EventArgs e)
        {
            leftTime--;
            if (leftTime == 0)
                this.Close();
            else
                skinLabel1.Text = leftTime.ToString();
        }
    }
}
